<?php

namespace App\Containers\AppSection\BankDetail\UI\API\Requests;

use App\Containers\AppSection\Ban\Traits\ProfilesBan;
use App\Containers\AppSection\Ban\Traits\UsersBan;
use App\Containers\AppSection\BankDetail\Traits\IsOwnerProfileTrait;
use App\Ship\Parents\Requests\Request;
use App\Ship\Traits\AccreditationStatusPermissionTrait;

class UpdateBankDetailRequest extends Request
{
    use AccreditationStatusPermissionTrait;
    use IsOwnerProfileTrait;
    use ProfilesBan;
    use UsersBan;

    /**
     * Define which Roles and/or Permissions has access to this request.
     */
    protected array $access = [
        'permissions' => '',
        'roles' => 'borrower|investor',
    ];

    /**
     * Id's that needs decoding before applying the validation rules.
     */
    protected array $decode = [
        // 'id',
    ];

    /**
     * Defining the URL parameters (e.g, `/user/{id}`) allows applying
     * validation rules on them and allows accessing them like request data.
     */
    protected array $urlParameters = [
        // 'id',
    ];

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'max:300'],
            'bik' => ['required', 'digits:9'],
            'correspondent_account' => ['required', 'digits:20'],
            'inn' => ['required', 'digits:10'],
            'checking_account' => ['required', 'digits:20'],
        ];
    }

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return $this->check([
            'hasAccess',
            'profileIsNotRejected',
            'isOwnerProfile',
            'profileIsNotBanned',
            'userIsNotBanned'
        ]);
    }
}
